<script lang="ts" setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { GetFukaOption } from '@/api/modules/fukaact'
import { GetFukaUserSummaryDeta } from '@/api/modules/fukaactUser'

// const imgDomain = 'https://img1.eprhan.cc'
const route = useRoute()
// const router = useRouter()
// const PageNumberCache = PageNumber()

// 查询表单
const findFrom = reactive({
  FukaActId: route.query.fukaActId as string,
})

const dataList: any = reactive({
  Obj: {},
})

const OptionList = reactive({
  fukaOption: [],
})

const loading = ref(true)

async function GetDataList() {
  const params = {
    ...(findFrom.FukaActId && { FukaActId: findFrom.FukaActId }),
  }
  await GetFukaUserSummaryDeta(params).then(async (dataRes: any) => {
    if (dataRes.succeeded) {
      dataList.Obj = dataRes.data
      loading.value = false
    }
    else {
      ElMessage.error(`查询失败。${dataRes.errors}`)
      loading.value = false
    }
  })
    .catch(() => {
      loading.value = false
    })
  loading.value = false
}

// 查询
function Inquire() {
  GetDataList()
}

// function SkipPage(name: any) {
//   router.push({
//     name: `${name}`,
//     query: {
//       fukaActId: findFrom.FukaActId,
//     },
//   })
// }

onMounted(async () => {
  // 获取福卡活动
  const fukaData: any = await GetFukaOption()
  if (fukaData.succeeded) {
    OptionList.fukaOption = fukaData.data
    if (route.query.fukaActId === undefined) {
      findFrom.FukaActId = fukaData.data[0].fukaActId
    }

    nextTick(() => {
      OptionList.fukaOption = fukaData.data
    })
  }

  if (findFrom.FukaActId) {
    GetDataList()
  }
  else {
    ElMessage.error('请选择福卡活动')
    loading.value = false
  }
})
</script>

<template>
  <div>
    <PageMain>
      <SearchBar :show-toggle="false">
        <div class="header">
          <el-form label-positio="right" label-width="auto">
            <div class="from">
              <el-form-item label="福卡活动">
                <el-select v-model="findFrom.FukaActId" filterable placeholder="请选择福卡活动">
                  <el-option v-for="item in (OptionList.fukaOption as any[])" :key="item.fukaActId" :label="(item.fukaActId as any)" :value="item.fukaActId" />
                </el-select>
              </el-form-item>
            </div>
          </el-form>
          <div class="text-right">
            <el-button @click="Inquire">
              查询
            </el-button>
          </div>
        </div>
      </SearchBar>
      <ElDivider border-style="dashed" />
      <el-divider content-position="left">
        总数
      </el-divider>
      <el-row>
        <el-col :span="5">
          <el-statistic title="参与总人数" :value="dataList.Obj.totalP" />
        </el-col>
        <el-col :span="5">
          <el-statistic title="兑奖总人数" :value="dataList.Obj.successP" />
        </el-col>
        <el-col :span="5">
          <el-statistic title="兑奖总次数" :value="dataList.Obj.successC" />
        </el-col>
        <el-divider content-position="left">
          抽奖数
        </el-divider>
        <el-col :span="5">
          <el-statistic title="拥有5张卡可兑换的总抽奖次数" :value="dataList.Obj.fiveC" />
        </el-col>
        <el-col :span="5">
          <el-statistic title="拥有抽奖机会的人数" :value="dataList.Obj.totalCP" />
        </el-col>
        <el-col :span="5">
          <el-statistic title="总计产生的抽奖机会" :value="dataList.Obj.totalC" />
        </el-col>
        <el-divider content-position="left">
          共计
        </el-divider>
        <el-col :span="4">
          <el-statistic title="A卡共计" :value="dataList.Obj.aCount" />
        </el-col>
        <el-col :span="5">
          <el-statistic title="B卡共计" :value="dataList.Obj.bCount" />
        </el-col>
        <el-col :span="5">
          <el-statistic title="C卡共计" :value="dataList.Obj.cCount" />
        </el-col>
        <el-col :span="5">
          <el-statistic title="D卡共计" :value="dataList.Obj.dCount" />
        </el-col>
        <el-col :span="5">
          <el-statistic title="E卡共计" :value="dataList.Obj.eCount" />
        </el-col>
        <el-divider content-position="left">
          拥有人数
        </el-divider>
        <el-col :span="4">
          <el-statistic title="同时拥有5张人数" :value="dataList.Obj.fiveP" />
        </el-col>
        <el-col :span="5">
          <el-statistic title="同时拥有4张人数" :value="dataList.Obj.fourP" />
        </el-col>
        <el-col :span="5">
          <el-statistic title="同时拥有3张人数" :value="dataList.Obj.threeP" />
        </el-col>
        <el-col :span="5">
          <el-statistic title="同时拥有2张人数" :value="dataList.Obj.twoP" />
        </el-col>
        <el-col :span="5">
          <el-statistic title="同时拥有1张人数" :value="dataList.Obj.oneP" />
        </el-col>
        <el-divider content-position="left">
          时间
        </el-divider>
        <el-col :span="8">
          <el-statistic title="数据更新时间" :value="dataList.Obj.updTime" />
        </el-col>
        <el-col :span="12">
          <el-statistic title="数据查询执行时间" :value="dataList.Obj.elapsedTime" />
        </el-col>
      </el-row>
    </PageMain>
  </div>
</template>

<style scoped>
.header {
  display: grid;
  grid-template-columns: 6fr 1fr;

  .from {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    grid-gap: 20px;

    .el-form-item {
      margin-bottom: 0;
    }
  }
}

.scrollbar-flex-content {
  display: flex;
  max-width: 300px;

  .scrollbar-flex-img {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: auto;
    height: 60px;
    margin-right: 10px;
  }
}

.user-name {
  display: flex;
  align-items: center;
  justify-content: left;

  div {
    text-align: left;
  }
}

.el-col {
  text-align: center;
}
</style>
